/**
 * 部门管理初始化
 */
var WholeHospital = {
    id: "WholeHospitalTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
WholeHospital.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {
            field: '',
            title: '',
            visible: false,
            formatter: function (value, row, index) {
                return index + 1;
            }
        },
        {
            title: '一级分类', field: 'rirstClassification', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                var dv = $("#dimensionSelection").val() + "," + value;
                if ((index + 1) % 5 == 1) {
                    return "<a href='javascript:;' onclick='WholeHospital.getDimension(" + '"' + dv + '"' + ")'>" + value + "</a>"
                } else {
                    return "";
                }
            }
        },
        {
            title: '新老客', field: 'newOldGuests', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if ((index + 1) % 5 == 1) {
                    return "新客首次";
                } else if ((index + 1) % 5 == 2) {
                    return "新客二次";
                } else if ((index + 1) % 5 == 3) {
                    return "新客";
                } else if ((index + 1) % 5 == 4) {
                    return "老客";
                } else if ((index + 1) % 5 == 0) {
                    return "合计";
                }
            }
        },
        {title: '门诊量', field: 'outpatientVolume', align: 'center', valign: 'middle', width: '50px'},
        {title: '成交量', field: 'volume', align: 'center', valign: 'middle', width: '50px'},
        {
            title: '成交率', field: 'turnoverRate', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (row.outpatientVolume == 0) {
                    return "0.00";
                } else {
                    return ((row.volume) / (row.outpatientVolume)).toFixed(2);
                }
            }
        },
        {
            title: '科室业绩', field: 'departmentPerformance', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (value == null || value == "") {
                    return "0.00";
                } else {
                    return value;
                }
            }
        },
        {
            title: '人均消费额', field: 'perCapitaConsumption', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {
                if (row.volume == 0) {
                    return "0.00";
                } else {
                    return ((row.departmentPerformance) / (row.volume)).toFixed(2);
                }
            }
        },
        {
            title: '门诊量占比', field: 'outpatientVolumeRatio', align: 'center', valign: 'middle', width: '50px',
            formatter: function (value, row, index) {

            }
        },
        {title: '成交量占比', field: 'volumeRatio', align: 'center', valign: 'middle', width: '50px'},
        {title: '成交额占比', field: 'turnoverRatio', align: 'center', valign: 'middle', width: '50px'},
        // {
        //     title: '操作', field: '', align: 'center', valign: 'middle', width: '50px',
        //     formatter: function (value, row, index) {
        //         return "<a href='javascript:;' onclick='WholeHospital.dimensionSelections(" + '"' + row.rirstClassification + ',department"' + ")'>[科室]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections2(" + '"' + row.rirstClassification + ',customerAge"' + ")'>[年龄]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections3(" + '"' + row.rirstClassification + ',medium"' + ")'>[媒介]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections4(" + '"' + row.rirstClassification + ',tcName"' + ")'>[TC]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections5(" + '"' + row.rirstClassification + ',doctor"' + ")'>[医生]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections6(" + '"' + row.rirstClassification + ',channel"' + ")'>[渠道]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections7(" + '"' + row.rirstClassification + ',cities"' + ")'>[城市]</a>" +
        //             "<a href='javascript:;' onclick='WholeHospital.dimensionSelections8(" + '"' + row.rirstClassification + ',occupation"' + ")'>[职业]</a>"
        //     }
        // },
    ]
    return columns;
};

/**
 * 检查是否选中
 */
WholeHospital.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        WholeHospital.seItem = selected[0];
        return true;
    }
};

WholeHospital.openChoiceDimensionTwo = function (dimensionChinaName) {
    var dimensionSelection = $("#dimensionSelection").val();
    var startTime =  window.parent.document.getElementById("startTime").value;
    var endTime =  window.parent.document.getElementById("endTime").value;
    var value = $("#value").val();
    var ddvse = dimensionSelection + "," + dimensionChinaName + "," + value + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddvse
    });
    this.layerIndex = index;
}

/**
 * 查询预约客户列表
 */
WholeHospital.search = function () {
    WholeHospital.table.refresh({query: WholeHospital.formParams()});
};

WholeHospital.openBillImport = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传账单明细',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/bill_import/'
    });
    this.layerIndex = index;
};

WholeHospital.openConsumerStatisticsImport = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传消费者统计',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/consumer_statistics/'
    });
    this.layerIndex = index;
};

WholeHospital.openTreatmentAnalysisImport = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传患者就诊分析数据',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/treatment_analysis/'
    });
    this.layerIndex = index;
};

WholeHospital.openOperationAnalysisImport = function () {
    var index = layer.open({
        type: 2,
        title: '批量上传运营分析统计数据',
        area: ['90%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/operation_analysis/'
    });
    this.layerIndex = index;
};


/**
 * 关闭此对话框
 */
WholeHospital.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}

WholeHospital.downLoadExcel = function () {
    // location.href = Feng.ctxPath + '/wholeHospital/getTemplateExcel?';
    location.href = Feng.ctxPath + '/wholeHospital/downloadExcelyyfx'
};


WholeHospital.downLoadExcels = function () {
    // location.href = Feng.ctxPath + '/wholeHospital/getTemplateExcel?';
    location.href = Feng.ctxPath + '/wholeHospital/downloadExcelyyfxs'
};

WholeHospital.resetSearch = function () {
    var myDate = new Date();
    var month;
    var day;
    if ((myDate.getMonth() + 1) < 10) {
        month = "0" + (myDate.getMonth() + 1);
    } else {
        month = "" + (myDate.getMonth() + 1);
    }
    if (myDate.getDate() < 10) {
        day = "0" + myDate.getDate();
    } else {
        day = "" + myDate.getDate();
    }
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    WholeHospital.search();
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
WholeHospital.formParams = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['dimensionSelection'] = $("#dimensionSelection").val();
    return queryData;
}

WholeHospital.dimensionSelections = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}

WholeHospital.getDimension = function (dv) {
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var dse = dv + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '维度选择',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getDimension/' + dse
    });
    this.layerIndex = index;
}

WholeHospital.dimensionSelections = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelection + "," + dimensionSelections + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections2 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections3 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections4 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections5 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections6 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections7 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}
WholeHospital.dimensionSelections8 = function (data) {
    var dimensionSelection = $("#dimensionSelection").val();
    var dimensionSelections = data;
    var startTime = $("#startTime").val();
    var endTime = $("#endTime").val();
    var ddse = dimensionSelections + "," + dimensionSelection + "," + startTime + "," + endTime;
    var index = layer.open({
        type: 2,
        title: '7X7报表',
        area: ['95%', '95%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/wholeHospital/to_getSevenReport/' + ddse
    });
    this.layerIndex = index;
}

$(function () {
    var myDate = new Date();
    var month;
    var day;
    if ((myDate.getMonth() + 1) < 10) {
        month = "0" + (myDate.getMonth() + 1);
    } else {
        month = "" + (myDate.getMonth() + 1);
    }
    if (myDate.getDate() < 10) {
        day = "0" + myDate.getDate();
    } else {
        day = "" + myDate.getDate();
    }
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    var defaultColunms = WholeHospital.initColumn();
    var table = new BSTable(WholeHospital.id, "/wholeHospital/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(WholeHospital.formParams());
    WholeHospital.table = table.init();
    WholeHospital.search();
});
